### -*- coding: utf-8 -*- #############################################
# Разработано компанией Ключевые Решения (http://keysolutions.ru/)
# Все права защищены, 2006-2007
#
# Developed by Key Solutions (http://keysolutions.ru/)
# All right reserved, 2006-2007
#######################################################################
"""ClosenessView class for the Zope 3 based diplom

$Id: closenessview.py 74 2008-03-12 11:26:17Z Arvi3D $
"""
__author__  = "Arvid"
__license__ = "ZPL"
__version__ = "$Revision: 74 $"
__date__ = "$Date: 2008-03-12 11:26:17 +0000 (Wed, 12 Mar 2008) $"

from zope.interface import Interface
from zope.app.i18n import ZopeMessageFactory as _
from zope.app import zapi

from distributingview import DistributingSelectionView
from diplom.interfaces import IDistributingFactory, IGenetic

class ClosenessView(DistributingSelectionView) :
    """Propability function view"""

    def getDataSetScript(self):
        ga_weight, ga_paramlist = IGenetic(self.context).ga
        factory1 = zapi.getUtility(IDistributingFactory, name = self.context.firstDistr, context = self.context)
        factory2 = zapi.getUtility(IDistributingFactory, name = self.context.secondDistr, context = self.context)
        return '<script type="text/javascript"> var dataset = {"closeness1":  %s, "closeness2":  %s, "ga closeness": %s };</script>' \
                % (list(self.lineCoordinates(lambda x : factory1.closeness(x, **dict(self.context.params[0])))),
                   list(self.lineCoordinates(lambda x : factory2.closeness(x, **dict(self.context.params[1])))),
                   list(self.lineCoordinates(lambda x : self.context.teoreticalCloseness(x, ga_weight, ga_paramlist))),
                   )
